*Bringing up the dataset.

use "C:\Dataset_Winning_Hearts"

*age
codebook Q101
tabulate Q101
mvdecode Q101, mv(997)

*sex
codebook Q102
tabulate Q102

*education
codebook Q103
tabulate Q103, nolabel
mvdecode Q103, mv(988)

*state of residence
codebook Q104
tabulate Q104, nolabel
tabulate Q104

*political orientation left vs. right
codebook Q105
tabulate Q105, nolabel
mvdecode Q105, mv(988)
tabulate Q105

*opinion about president Maduro
codebook Q106
mvdecode Q106, mv(988)
tabulate Q106

*support president's government or opposition
codebook Q107
mvdecode Q107, mv(988)
tabulate Q107,

*Knowledge of sanctions.
codebook Q51
tabulate Q51, nolabel
mvdecode Q51, mv(988)

*------------------------------------------------------------------.
*data trimming.
*creating new dependent var, numeric variables with highscore = positive.

gen sfav1 = Q48_version1
gen sfav2 = Q48_version2
gen sfav3 = Q48_version3
gen sfav4 = Q48_version4
mvdecode sfav1, mv(988)
mvdecode sfav2, mv(988)
mvdecode sfav3, mv(988)
mvdecode sfav4, mv(988)

*creating dep variable with answer to any scenario, removing missing.

gen sfav = max(sfav1, sfav2, sfav3, sfav4) if missing(sfav1, sfav2, sfav3, sfav4)

recode sfav(988=.)

table sfav

*creating variable: sank against maduro or Venezuela?. 1 = Maduro.
recode Q48_split(2 4=0)(1 3=1), gen(maduro)
label variable maduro "Maduro (vs. Venezuela)"
gen madurocop = maduro
label variable madurocop "Maduro (vs. Venezuela)"

recode Q48_split(2 4=1)(1 3=0), gen(venezuela) 

*creating variable: sank to stop violence or threat against US. 1 = violence.
recode Q48_split (1 2=1)(3 4=0), gen(violence)
label variable violence "Violence (vs. Threat to the USA)"
gen violencecop = violence
label variable violencecop "Violence(vs. Threat to the USA)"

recode Q48_split (1 2=1)(3 4=0), gen(threat)

*rescaling variables.
sum sfav
gen supsa = (sfav - r(min)) / (r(max) - r(min))
sum Q102
gen fem = (Q102 - r(min)) / (r(max) - r(min))
sum Q103
gen uni = (Q103 - r(min)) / (r(max) - r(min))
recode Q104(1=1)(else=0), gen(loc)
sum Q105
gen left = (Q105 - r(min)) / (r(max) - r(min))
sum Q106
gen reg = (Q106 - r(min)) / (r(max) - r(min))
sum Q107
gen opp = (Q107 - r(min)) / (r(max) - r(min))
sum Q51
gen kno = (Q51 - r(min)) / (r(max) - r(min))

*Table 2.
summarize sfav
summarize Q101
summarize Q102
summarize Q103
summarize Q104
summarize Q105
summarize Q106
summarize Q107

*Table 3.
*manipulation check: age, gender, education, location, left-right.
*political position, government or opposition.

recode Q48_split(1=1)(2 3 4=0), gen(mpc1)

recode Q48_split(2=1)(1 3 4=0), gen(mpc2)

recode Q48_split(3=1)(1 2 4=0), gen(mpc3)

recode Q48_split(4=1)(1 2 3=0), gen(mpc4)

mean Q101

mean Q101 if mpc1==1

mean Q101 if mpc2==1

mean Q101 if mpc3==1

mean Q101 if mpc4==1

mean fem

mean fem if mpc1==1

mean fem if mpc2==1

mean fem if mpc3==1

mean fem if mpc4==1

mean uni

mean uni if mpc1==1

mean uni if mpc2==1

mean uni if mpc3==1

mean uni if mpc4==1

mean loc

mean loc if mpc1==1

mean loc if mpc2==1

mean loc if mpc3==1

mean loc if mpc4==1

mean left

mean left if mpc1==1

mean left if mpc2==1

mean left if mpc3==1

mean left if mpc4==1

mean reg

mean reg if mpc1==1

mean reg if mpc2==1

mean reg if mpc3==1

mean reg if mpc4==1

mean opp

mean opp if mpc1==1

mean opp if mpc2==1

mean opp if mpc3==1

mean opp if mpc4==1

*Table 4.
tabulate Q48_split, summarize(supsa)

*--------------------------------------------------------------------------------
*Table 5.
*experiment.
reg supsa maduro violence
reg supsa maduro violence Q101 Q102 Q103 Q104 Q105 Q106 Q107
reg supsa i.maduro##i.violence
reg supsa i.maduro##i.violence Q101 Q102 Q103 Q104 Q105 Q106 Q107

*Table 8.
*ordered logit experiments.
ologit supsa maduro violence
ologit supsa maduro violence Q101 Q102 Q103 Q104 Q105 Q106 Q107
ologit supsa i.maduro##i.violence
ologit supsa i.maduro##i.violence Q101 Q102 Q103 Q104 Q105 Q106 Q107

*Figure 1.
mean supsa if maduro == 1
estimate store madurofig1
gen supsaa = supsa
mean supsaa if maduro == 0
estimate store venezuelafig1
gen supsab = supsa
mean supsab if violence == 1
estimate store violencefig1
gen supsac = supsa
mean supsac if violence == 0
estimate store threatfig1

coefplot (madurofig1) (venezuelafig1) (violencefig1) (threatfig1), graphregion(color(white)) ///
color(black) ciopts(lcolor(gs0)) mlabcolor(gs0) bgcolor(white) nooffsets mlabel format(%9.2g) ///
mlabposition(9) vertical legend(off) yscale(r(.6)) ylabel(.6 .7 .8) xscale(r(.2)) grid(none) ///
rename(supsa = "Maduro" supsaa = "Venezuela" supsab = "Violence" supsac = "Threat") ytitle(Support for sanctions)

*Figure 2.
reg supsa maduro violence
estimates store sanormal

reg supsa i.maduro##i.violence
estimates store sainteractionx

recode maduro(1=0)(0=1), gen(madurotest)
recode violence(1=0)(0=1), gen(violencetest)
gen violencex = violence

reg supsa i.madurotest##i.violencex
estimates store sainteractiony

coefplot (sanormal) ///
, drop(_cons 1.madurotest) ///
xline(0, lcolor(black) lpattern(dash)) graphregion(color(white)) color(black) ///
ciopts(lcolor(gs0)) mlabcolor(gs0) bgcolor(white) nooffsets level(90) ///
xscale(r(-.2 .2)) xlabel(-.2 -.1 0 .1 .2) scale(0.80) ///
mlabel format(%9.2g) mlabposition(12) grid(none) legend(off)

*experiments and view of the president without controls.
reg supsa i.Q106##i.maduro i.Q106##i.violence

*Table 6 and Table 7.
*Figure 3.
reg supsa i.Q106##i.maduro i.Q106##i.violence Q101 Q102 Q103 Q104 Q105
margins, dydx(maduro) over(Q106)
marginsplot, recast(scatter) yline(0, lcolor(gs0)) xscale(range(0.5 4.5)) xtitle("") title("") ytitle("Maduro effect on support for sanctions") ///
graphregion(color(white)) xlabel(,labsize(small)) ylabels(-0.4 (0.1) 0.4) level(90) ciopts(lcolor(gs0)) bgcolor(white)

reg supsa i.Q106##i.violence i.Q106##i.maduro Q101 Q102 Q103 Q104 Q105
margins, dydx(violence) over(Q106)
marginsplot, recast(scatter) yline(0, lcolor(gs0)) xscale(range(0.5 4.5)) xtitle("") title("") ytitle("Violence effect on support for sanctions") ///
graphregion(color(white)) xlabel(,labsize(small)) ylabels(-0.4 (0.1) 0.4) level(90) ciopts(lcolor(gs0)) bgcolor(white)
